package com.example.designpatterns.iterator.concrete;

import com.example.designpatterns.iterator.Iterator;

/**
 * 图书迭代器 - 具体迭代器类
 * 遍历图书集合中的所有图书
 */
public class BookIterator implements Iterator<Book> {
    private BookCollection bookCollection;
    private int currentIndex;
    
    /**
     * 创建图书集合的迭代器
     * @param bookCollection 图书集合
     */
    public BookIterator(BookCollection bookCollection) {
        this.bookCollection = bookCollection;
        this.currentIndex = 0;
    }
    
    @Override
    public boolean hasNext() {
        return currentIndex < bookCollection.getLength();
    }
    
    @Override
    public Book next() {
        if (!hasNext()) {
            return null;
        }
        
        Book book = bookCollection.getBookAt(currentIndex);
        currentIndex++;
        return book;
    }
    
    @Override
    public void remove() {
        throw new UnsupportedOperationException("图书迭代器不支持移除操作");
    }
} 